package com.qimei.onerice.servlet;

import com.qimei.onerice.entity.Comment;
import com.qimei.onerice.service.impl.CommentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/comment")
public class CommentServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");

		String comment = request.getParameter("comment");
		int customerId = Integer.parseInt(request.getParameter("customerId"));
		int dishId = Integer.parseInt(request.getParameter("dishId"));
		System.out.println(customerId);

		// 创建一个 GameComment 对象
		Comment newComment = new Comment();
		newComment.setComment(comment);
		newComment.setCustomerId(customerId);
		newComment.setDishId(dishId);
		newComment.setCommentDate(new Date());

		System.out.println(newComment);

		// 调用服务方法添加新游戏评论
		boolean success = new CommentServiceImpl().addComment(newComment);
		request.getRequestDispatcher("/view/dishInfo.jsp").forward(request, response);
	}
}
